<html>
<head>
<script>
if (window.testRunner) {
  testRunner.dumpAsText();
  testRunner.waitUntilDone();
}

document.cookie = 'cookie=parent';

function log(msg) {
  var line = document.createElement('div');
  line.appendChild(document.createTextNode(msg));
  document.getElementById('console').appendChild(line);
}

var testStarted = false;
function doTest() {
  if (testStarted)
    return;

  testStarted = true;
  frames[0].location = "javascript:" +
      "window.myopen = function(i) { frames[i].document.open(); };" +
      "window.mywrite = function(i, str) { frames[i].document.write(str); };" +
      "window.mywriteln = function(i, str) { frames[i].document.writeln(str); };" +
      "window.myclose = function(i) { frames[i].document.close(); };" +
      "parent.log('Helpers loaded!\\n');" +
      "parent.setTimeout('continueTest()', 10);";
}

function continueTest() {
  frames[0].location = "javascript:" +
      "window.myopen = function(i) { frames[i].document.open(); };" +
      "window.mywrite = function(i, str) { frames[i].document.write(str); };" +
      "window.mywriteln = function(i, str) { frames[i].document.writeln(str); };" +
      "window.myclose = function(i) { frames[i].document.close(); };" +
      "parent.log('Helpers loaded!\\n');";

  log('--- Test begins ---\n');
  log('* "about:blank"\n');
  log('document.URL = ' + frames[0].frames[0].document.URL + '\n');
  log('document.baseURI = ' + frames[0].frames[0].document.baseURI + '\n');
  log('document.cookie = ' + frames[0].frames[0].document.cookie + '\n');
  log('* ""\n');
  log('document.URL = ' + frames[0].frames[1].document.URL + '\n');
  log('document.baseURI = ' + frames[0].frames[1].document.baseURI + '\n');
  log('document.cookie = ' + frames[0].frames[1].document.cookie + '\n');
  log('--- After document.open() ---\n');
  frames[0].mywriteln(0, "Hello, world.");
  frames[0].mywriteln(1, "Hello, world.");
  log('* "about:blank"\n');
  log('document.URL = ' + frames[0].frames[0].document.URL + '\n');
  log('document.baseURI = ' + frames[0].frames[0].document.baseURI + '\n');
  log('document.cookie = ' + frames[0].frames[0].document.cookie + '\n');
  log('* ""\n');
  log('document.URL = ' + frames[0].frames[1].document.URL + '\n');
  log('document.baseURI = ' + frames[0].frames[1].document.baseURI + '\n');
  log('document.cookie = ' + frames[0].frames[1].document.cookie + '\n');
  log('--- After document.close() ---\n');
  frames[0].myclose(0);
  frames[0].myclose(1);
  log('* "about:blank"\n');
  log('document.URL = ' + frames[0].frames[0].document.URL + '\n');
  log('document.baseURI = ' + frames[0].frames[0].document.baseURI + '\n');
  log('document.cookie = ' + frames[0].frames[0].document.cookie + '\n');
  log('* ""\n');
  log('document.URL = ' + frames[0].frames[1].document.URL + '\n');
  log('document.baseURI = ' + frames[0].frames[1].document.baseURI + '\n');
  log('document.cookie = ' + frames[0].frames[1].document.cookie + '\n');
  log('--- Test ends ---\n');

  testRunner.notifyDone();
}
</script>
</head>
<body>
<iframe 
  onload="doTest()"
  src="resources/iframe-with-about-blank-children.html">
</iframe>
<div id="console"></div>
</body>
</html>
